package org.lim.shared.websocket.service;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class PictureEditStateService {
    
    // 每张图片的编辑状态，key:图片id，value:用户id
    private final Map<Long, Long> pictureEditingUsers = new ConcurrentHashMap<>();
    
    /**
     * 检查图片是否被其他用户编辑
     */
    public boolean isEditingByOthers(Long pictureId) {
        return pictureEditingUsers.containsKey(pictureId);
    }
    
    /**
     * 设置编辑用户
     */
    public void setEditingUser(Long pictureId, Long userId) {
        pictureEditingUsers.put(pictureId, userId);
    }
    
    /**
     * 获取编辑用户ID
     */
    public Long getEditingUserId(Long pictureId) {
        return pictureEditingUsers.get(pictureId);
    }
    
    /**
     * 移除编辑用户
     */
    public void removeEditingUser(Long pictureId) {
        pictureEditingUsers.remove(pictureId);
    }
}